<?php
namespace app\index\controller;
use think\Controller;
use think\Session;
use think\Db;
use app\index\controller\Base;
class Content extends Base{
	//发布文章内容页
    public function index(){
    $pid=input('pid');
    //$pubs 显示文章的内容 查询了文章表和用户表
    $pubs=Db::table('produce')->alias('a')->join('user b','a.userid=b.id')->where('pid',$pid)->select();
    $this->assign('pubs',$pubs);   
    $comment=db('comment')->alias('c')
    ->join('user b','c.uid=b.id')
    ->where('wid',$pid)->select();
    $this->assign('comment',$comment);   
		return $this->fetch('content');
    }
    public function dianzan(){
      if(!Session::get('username')){
          $this->success('请先登陆！','Reg/index');
       }else{
          $blid=input("blid");
          $info=Db::table('produce')->where('pid',$blid)->setInc('thumb');
          if($info){
            $this->success('点赞成功！','Blog/index');
          }else{
            $this->error('点赞失败！');
          }
        }
    }

    public function comment(){
      $coid=input('coid');
      $username=Session::get('username');
      $user=db('user')->where('username',$username)->column('id');
			$userid=$user[0];
    	$comment=input('post.comment');
    	$comment_time=date("Y-m-d H:i:s");
    	$data=[
    		'wid'=>$coid,
    		'content'=>$comment,
    		'uid'=>$userid,
    		'time'=>$comment_time,
    	];
    	if(!Session::get('username')){
    		$this->success('请先登陆！','reg/index');
    	}else{
    		if(db('comment')->insert($data)){
	    		echo "<script type='text/javascript'>alert('评论成功！');location='javascript:history.back()';</script>";    
	    	}else{
	    		$this->error('评论失败！');
	    	}
    	}
    }
	
}